package com.kb5173.base.demo.original.hessian;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder;

import com.caucho.hessian.server.HessianSkeleton;
import com.kb5173.base.demo.protocal.DemoServiceApi;

public class HessianExport {

	public static void main(String[] args) {
		
		HessianExport hoe = new HessianExport();
		DemoServiceOriginHessianImpl dhi = new DemoServiceOriginHessianImpl();
		hoe.export(dhi, DemoServiceApi.class);
		hoe.start();
	}

	public void export(Object impl, Class<?> cls) {
		HessianSkeleton hs = new HessianSkeleton(impl, cls);
		MyHttpServlet.addSkelon(cls.getName(), hs);
	}

	public void start() {

		Server server = new Server();
		SelectChannelConnector scc = new SelectChannelConnector();
		scc.setPort(9091);
		server.addConnector(scc);

		ServletHandler handler = new ServletHandler();
		ServletHolder holder = handler.addServletWithMapping(
				MyHttpServlet.class, "/*");
		holder.setInitOrder(1);
		server.addHandler(handler);
		try {
			server.start();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
